import mysql.connector

# 数据库连接配置
db = mysql.connector.connect(
    host='localhost',
    user='root',
    password='123456',
    database='assess'
)
cursor = db.cursor()

# 读取数据库中location列的所有内容
cursor.execute("SELECT id, location FROM developer")
locations = cursor.fetchall()

for row in locations:
    
    location_id = row[0]
    location_text = row[1]
    
    # 如果location为空，则设置为“未知”
    if location_text is None or location_text.strip() == "":
        translated_text = "未知"
        print(f"{location_id} 的位置为空，更新为：{translated_text}")
        
        # 更新数据库中的位置为“未知”
        update_query = "UPDATE developer SET location = %s WHERE id = %s"
        cursor.execute(update_query, (translated_text, location_id))
        db.commit()
    else:
        print(f"{location_id} 的位置不为空，无需更新")


# 关闭数据库连接
cursor.close()
db.close()
